home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr53 / pctv4n_1.zip / STACK.CPP < prev    next >
Text File  |  1993-06-10  |  1KB  |  55 lines

  1. #include <dos.h>
  2. #include <mem.h>
  3.  
  4. #if sizeof(void *) != sizeof(void far *)
  5. #error This code assumes a large data model.
  6. #endif
  7.  
  8. // Skip first 512 bytes to accommodate emulator.
  9. #define TEST_BASE  0x0200
  10. #define STACK_VAL  0x66
  11.  
  12. ///
  13. // Fill stack with STACK_VAL.
  14. void fillStack() {
  15. asm {
  16. mov     ax, ss          // Point ES:DI to SS:TEST_BASE.
  17. mov     es, ax
  18. mov     di, TEST_BASE
  19.  
  20. mov     al, STACK_VAL   // STACK_VAL marks unused stack.
  21.  
  22. cld                     // Forward store.
  23.  
  24. mov     cx, sp          // Stack pointer minus TEST_BASE
  25. sub     cx, TEST_BASE   // is length of store.
  26.  
  27. rep     stosb           // Fill stack.
  28. }
  29. }
  30.  
  31. ///
  32. // Check stack watermark.
  33. unsigned stackMin() {
  34. asm {
  35. mov     ax, ss          // Point ES:DI to SS:TEST_BASE.
  36. mov     es, ax
  37. mov     di, TEST_BASE
  38.  
  39. mov     al, STACK_VAL   // STACK_VAL marks unused stack.
  40.  
  41. cld                     // Forward search.
  42.  
  43. mov     cx, _stklen     // Stack length minus TEST_BASE
  44. sub     cx, TEST_BASE   // is length of search.
  45.  
  46. repe    scasb           // Find first non-matching byte.
  47.  
  48. dec     di              // DI holds offset after first byte
  49. mov     ax, di          // that doesn't match.
  50. }
  51.  
  52. // Return value is amount of stack still free.
  53. return (_AX);
  54. }
  55.